package com.csy.property.community.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.csy.commons.vo.AjOwnerVo;
import com.csy.feign.user.api.UserServiceApi;
import com.csy.property.community.domain.AjCommunityInteraction;
import com.csy.property.community.mapper.AjCommunityInteractionMapper;
import com.csy.property.community.service.AjCommunityInteractionService;

import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 社区互动实现类
 */
@Service
@Slf4j
public class AjCommunityInteractionImpl implements AjCommunityInteractionService {

    @Resource
    private AjCommunityInteractionMapper ajCommunityInteractionMapper;
    @Resource
    private UserServiceApi userServiceApi;
    @Override
    public List<AjCommunityInteraction> selectCommunityInteractionList(AjCommunityInteraction ajCommunityInteraction) {
        return ajCommunityInteractionMapper.selectCommunityInteractionList(ajCommunityInteraction);
    }


    @Override
    public int add(AjCommunityInteraction ajCommunityInteraction) {
        ajCommunityInteraction.setInteractionId(IdUtil.getSnowflakeNextId());
        try {
            AjOwnerVo owner = userServiceApi.getOwnerByName(ajCommunityInteraction.getOwnerRealName());
            ajCommunityInteraction.setUserId(owner.getOwnerId());
        }catch (Exception e){
            log.error("服务调用失败！",e);
        }

        return ajCommunityInteractionMapper.insert(ajCommunityInteraction);
    }

    @Override
    public int deleteById(String id) {

        return ajCommunityInteractionMapper.deleteById(id);
    }
}
